#include "Fighter.h"
#include <iostream>

Fighter::Fighter(ISceneManager *smgr) {

	IAnimatedMesh* mesh = smgr->getMesh("../media/cubo.ms3d");
	_smgr = smgr;
	_fighter = smgr->addMeshSceneNode(mesh->getMesh(0));
	_fighter->setScale(irr::core::vector3df(0.25,0.25,0.25));
        _fighter->setPosition(vector3df(10,10,10));
        setColor(0,255,0);
	
}

void Fighter::update(irr::u32 current_time, irr::u32 last_time)
{
	
}

ISceneNode* Fighter::getSceneNode()
{
	return _fighter;
}

void Fighter::move(core::vector3df destination)
{
    _fighter->removeAnimators();
        irr::core::vector3df move = destination - _fighter->getPosition();
	ISceneNodeAnimator* anim = _smgr->createFlyStraightAnimator(_fighter->getPosition(), destination, irr::core::floor32(100*move.getLength()), false);
	_fighter->addAnimator(anim);
	anim->drop();
	move.normalize();
        f64 angle = RADTODEG * acos(vector3df(1,0,0).dotProduct(move));
        if(destination.Z > _fighter->getPosition().Z)
			angle = -angle;
		std::cout << "bolos: "<< angle<<"\n";
		//_fighter->rotateXZBy(angle, _fighter->getPosition());
        vector3df rotation = _fighter->getRotation();
        _fighter->setRotation(vector3df(0,angle,0));
        //_fighter->addAnimator(anim);
        //anim->drop();
}

void Fighter::setColor(u32 r, u32 g, u32 b)
{
   _fighter->getMaterial(0).EmissiveColor.set(255, r, g, b); 

}
